<?php

require_once('AnalyzeStrategyInterface.php');

class RepeatLettersAnalyzeStrategy implements AnalyzeStrategyInterface {
    
    /**
     *
     * @param string $string
     * @return array
     */
    public function analyze($string) {  
        $stats = array();
        
        for ($i = 0; $i < strlen($string); $i++) {
            $letter = $string[$i];
            
            if (!in_array($letter, array_keys($stats))) {
                $repeats = 1;
                for ($j = $i + 1; $j < strlen($string); $j++) {
                    if ($letter == $string[$j]) {
                        $repeats++;
                    }
                }
                
                if ($repeats > 1) {
                    $stats[$letter] = $repeats;
                }
                
            }
        }
        
        return $stats;
    }
}